import {
  CoolController,
  BaseController,
  CoolUrlTag,
  TagTypes,
  CoolTag,
  CoolCommException
} from '@cool-midway/core';
import { Body, Inject, Post,Files,Fields } from '@midwayjs/core';
import { UserWxService } from '../../service/wx';
import { UserInfoService } from '../../service/info';
import { UserEmailService } from '../../service/email';
/**
 * 通用
 */
@CoolUrlTag()
@CoolController()
export class UserCommController extends BaseController {
  @Inject()
  userWxService: UserWxService;

  @Inject()
  userInfoService: UserInfoService;

  @Inject()
  userEmailService: UserEmailService;

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/wxMpConfig', { summary: '获取微信公众号配置' })
  public async getWxMpConfig(@Body('url') url: string) {
    return this.ok(await this.userWxService.getWxMpConfig(url));
  }

  @Post('/upload', { summary: '上传文件' })
  public async upload(@Files() files, @Fields() fields) {
    // 上传文件
    const url = await this.userInfoService.uploadFile({files,fields});
    return this.ok({url});
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/emailCode', { summary: '发送邮箱验证码' })
  public async emailCode(@Body() body) {
    return this.ok(await this.userEmailService.sendCode(body));
  }
  
}
